
*** Set Fixed Effects and Clustering
global fe "courtq"
global clusvar "partyr"

capture frame drop linking 
frame create linking str55 outcome str55 descr beta se N 

preserve

*** Regress match on stringency
eststo hra: reghdfe thematch stringency, absorb($fe) cluster($clusvar)
frame post linking ("Match to Benefits") ("Coef on Stringency, no controls") (_b[stringency]) (_se[stringency]) (e(N))
estadd local Controls "No"
estadd local timefe "Yes"

label var evictionorder "Evicted"
label var iblack "Black (Predicted)"
label var ifemale "Female (Predicted)"
label var iwhite "White (Predicted)"
label var ihisp "Hispanic (Predicted)"
gen amountowed=exp(logclaim)/1000

label var noattorney "Tenant Without Attorney"
label var amountowed "Amount Rent (1000's)"
label var sh_hhpov "Tract Poverty Rate"
label var lmrent "Tract Median Rent"

label var stringency "Stringency"
label var evictionorder "Evicted"

global controls "amountowed iblack ihisp ifemale noattorney sh_hhpov lmrent"

eststo hra2: reghdfe thematch evictionorder, absorb($fe) cluster($clusvar)
estadd local Observations "`=e(N)'"

eststo hra3: reghdfe thematch stringency $controls, absorb($fe) cluster($clusvar)
estadd local Observations "`=e(N)'"

frame post linking ("Match to Benefits") ("Coef on Stringency, with controls") (_b[stringency]) (_se[stringency]) (e(N))

esttab hra2 hra3 using ${Inputs}\NY_haslink.tex, label  replace noobs nocons b(3) se(3) nomtitles order(evictionorder stringency $controls) mgroups("Matched to Benefits", pattern(1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) scalar("Observations") 

restore


********************************
**** Stringency - Link *********
********************************

*** Set general controls
global exactcontrols "black hisp female blackfemale hispfemale  ageatfiling age2 age3 sh_hhpov med_grossrent rentowed multicase"

eststo ssnmiss: reghdfe missingssn stringency, absorb($fe) cluster($clusvar)

frame post linking ("Missing SSN") ("Coef on Stringency") (_b[stringency]) (_se[stringency]) (e(N))
estadd local Controls "No"
estadd local timefe "Yes"

eststo ssnmiss: reghdfe missingssn stringency $exactcontrols, absorb($fe) cluster($clusvar)
frame post linking ("Missing SSN") ("Coef on Stringency, with controls") (_b[stringency]) (_se[stringency]) (e(N))
estadd local Controls "No"
estadd local timefe "Yes"

frame linking: save ${Inputs}\NY_linking, replace



********************************
**** Stringency - Attrition ****
********************************
capture frame drop attrition 
frame create attrition str55 outcome str50 controls beta se N 

replace samp=(sentDOL==1)

global earningsvars "lquartearn1 lquartearn2 lquartearn3 lquartearn4 lemployedquart1 lemployedquart2 lemployedquart3 lemployedquart4 lavg2yrearn lavg2yremply"

global controls "$exactcontrols $earningsvars"

eststo alab1: reghdfe anypost_employ stringency  if samp==1, absorb($fe) cluster($clusvar)
frame post attrition ("Any Post Earnings") ("No Controls") (_b[stringency]) (_se[stringency]) (e(N))

eststo alab2: reghdfe anypost_employ stringency $controls  if samp==1, absorb($fe) cluster($clusvar)
frame post attrition ("Any Post Earnings") ("with Controls") (_b[stringency]) (_se[stringency]) (e(N))

eststo alab3: reghdfe anypost_employafterq4 stringency if samp==1, absorb($fe) cluster($clusvar)
frame post attrition ("Any Post Earnings Q4+") ("No Controls") (_b[stringency]) (_se[stringency]) (e(N))

eststo alab4: reghdfe anypost_employafterq4 stringency $controls   if samp==1, absorb($fe) cluster($clusvar)
frame post attrition ("Any Post Earnings Q4+") ("with Controls") (_b[stringency]) (_se[stringency]) (e(N))

eststo alab5: reghdfe anypost_employafterq8 stringency if samp==1, absorb($fe) cluster($clusvar)
frame post attrition ("Any Post Earnings Q8+") ("No Controls") (_b[stringency]) (_se[stringency]) (e(N))

eststo alab6: reghdfe anypost_employafterq8 stringency $controls if samp==1, absorb($fe) cluster($clusvar)
frame post attrition ("Any Post Earnings Q8+") ("with Controls") (_b[stringency]) (_se[stringency]) (e(N))

global controls "$exactcontrols"
eststo aben: reghdfe anypostbene stringency  if samp==1, absorb($fe) cluster($clusvar)
frame post attrition ("Any Post Benefits") ("No Controls") (_b[stringency]) (_se[stringency]) (e(N))
estadd local Controls "No"
estadd local timefe "Yes"

eststo aben: reghdfe anypostbene stringency $controls if samp==1, absorb($fe) cluster($clusvar)
frame post attrition ("Any Post Benefits") ("with Controls") (_b[stringency]) (_se[stringency]) (e(N))
estadd local Controls "No"
estadd local timefe "Yes"

eststo ahosp: reghdfe anyhosp stringency if samp==1, absorb($fe) cluster($clusvar)
frame post attrition ("Any Post Hospitalization") ("No Controls") (_b[stringency]) (_se[stringency]) (e(N))
estadd local Controls "No"
estadd local timefe "Yes"
eststo ahosp: reghdfe anyhosp stringency $controls if samp==1, absorb($fe) cluster($clusvar)
frame post attrition ("Any Post Hospitalization") ("with Controls") (_b[stringency]) (_se[stringency]) (e(N))
estadd local Controls "No"
estadd local timefe "Yes"

eststo postob: reghdfe somepost stringency if samp==1, absorb($fe) cluster($clusvar)
frame post attrition ("Any Post Record") ("No Controls") (_b[stringency]) (_se[stringency]) (e(N))
estadd local Controls "No"
estadd local timefe "Yes"

eststo postob: reghdfe somepost stringency $controls if samp==1, absorb($fe) cluster($clusvar)
frame post attrition ("Any Post Record") ("with Controls") (_b[stringency]) (_se[stringency]) (e(N))
estadd local Controls "No"
estadd local timefe "Yes"

frame attrition: save ${Inputs}\NY_attrition, replace



